import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DBConnection {

	// Configuration Stuff
	private String dbClass = "com.mysql.jdbc.Driver";
	private String dbUrl = "jdbc:mysql://www.drowne.com/drowecom_has";
	private String dbUser = "drowecom_has";
	private String dbPassword = "hideandseek2010";
	
	// Connection Configurations
	static Connection con;
	static Statement stmt;
	
	// Return Statements Configurations
	private String dbResponse="";
		
	public boolean connect() {
		try {
			// Connect to the database
			Class.forName(dbClass);
			con = DriverManager.getConnection (dbUrl, dbUser, dbPassword);
			stmt = (Statement) con.createStatement();
			return true;
		} //end try

		catch(ClassNotFoundException e) {
			e.printStackTrace();
		}

		catch(SQLException e) {
			e.printStackTrace();
		}
		return true;
	}
	
	public String query(String q) throws SQLException {
		// Execute the Query
		ResultSet rs = ((java.sql.Statement) stmt).executeQuery(q);

		while (rs.next()) {
			dbResponse = rs.getString(1);
			
		} //end while
		
		// ### DEBUG ###
		System.out.println(dbResponse);
		
		return dbResponse;
	}
	
	public void closeConnection() throws SQLException {
		con.close();
	}
	
}
